<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" href="/css/pintuer.css">
    <link rel="stylesheet" href="/css/admin.css">
    <script type="text/javascript" src="/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="/js/vue.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script type="text/javascript" src="/layui/layui.js"></script>
</head>
<body>
<div class="panel admin-panel" id="app">
    <div class="panel-head" id="add">
        <strong><span class="icon-pencil-square-o"></span>更新户型图</strong>
    </div>
    <div class="body-content">
        <form id="form" class="form-x">
            <div class="form-group">
                <div class="label">
                    <label>项目id：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" id="planProjectId" v-if="designer!=null"
                           v-model="designer.planProjectId"/>
                </div>
            </div>

            <div class="form-group">
                <div class="label">
                    <label>审核状态：</label>
                </div>
                <select class="input" id="constructionStatus"
                        style="width: 200px; line-height: 17px;">
                    <option value=2>未审核</option>
                </select>
            </div>

            <div class="label" id="addDiv" style="margin-left:95px">
                <label>户型图：</label>
            </div>

            <div><img style="margin-left:90px" id="image" :src="designer.planDesignPaper" width="100px">
                <button style="margin-left:20px" class="layui-btn" type="button"
                        @click="check(designer.planDesignPaper)">查看
                </button>
                <button class="layui-btn layui-btn-danger" type="button" @click="update(designer.planId)">更新</button>
            </div>
            <br>
            <div class="form-group">
                <br><br>
                <div class="field" style="margin-left:90px">
                    <button class="button bg-main icon-check-square-o" type="button" onclick="updateAccount()">
                        提交
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>

<script type="text/javascript">

    // var html="<div> <br><input type='file'  multiple='multiple'  name='myfile' id='img' />";
    // //var up="<button type='button' class='layui-btn test1' id='test1'> <i class='layui-icon'>&#xe67c;</i>上传图片 </button>"
    // function addOne() {
    // 	// document.getElementById("addDiv").innerHTML += "<div> <input type='file' name='myfile' id='img' />"
    // 	$("#addDiv").append(html);
    // }
    var id = location.href.split("?")[1].split("=")[1];

    var _this;
    var app = new Vue({
        el: "#app",
        data: {
            designer: null

        },
        created: function () {
            _this = this;
            this.selectById();
        },
        methods: {

            selectById: function () {
                $.ajax({
                    url: "/plan/selectById",
                    type: "get",
                    data: {"id": id},
                    dataType: "json",
                    success: function (data) {
                        _this.designer = data.obj;

                    }
                })
            },
            check: function (i) {
                location.href = i;
            },


            update: function (o) {
                layui.use('layer', function () {
                    var layer = layui.layer;
                    layer.open({
                        type: 2,
                        title: '更新图片',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['400px', '100%'],
                        content: ' updatepic.html?id=' + o,
                    });
                });

            }
        }
    });

    function updateAccount() {
        if (confirm("确定更新吗？")) {
            $.ajax({
                url: "/plan/update",
                type: "post",
                data: {
                    planId: id,
                    planProjectId: $("#planProjectId").val(),
                    planStatus: $("#planStatus").val(),
                    planDesignPaper: $("#image").attr("src"),
                },
                dataType: "json",
                success: function (data) {
                    alert("更新成功");
                    location.href = "plan.html";
                },
                error: function (error) {
                    alert("更新失败");
                    location.href = "plan.html";
                }
            })
        }
    }

</script>
</html>

